{
 "metadata": {
  "name": "",
  "signature": "sha256:75c955f2817ddd218c0587d52434ae0fe724eb60cbea04e22954435ad4f83f9f"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "In this notebook, we'll compare MultiIndex and String representations of measurements."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import print_function, division\n",
      "import pandas as pd\n",
      "from numpy.random import randn\n",
      "from StringIO import StringIO"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 25
    },
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Creating and reading in data"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Create DataFrames from random data"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "MultiIndex"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "columns_tuples = [('power', 'active'),\n",
      "                  ('power', 'apparent'),\n",
      "                  ('energy', 'active'),\n",
      "                  ('energy', 'apparent'),\n",
      "                  ('voltage', '')]\n",
      "\n",
      "index = pd.MultiIndex.from_tuples(columns_tuples, names=['physical quantity', 'type']) \n",
      "\n",
      "pd.DataFrame(randn(2,5), columns=index)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr>\n",
        "      <th>physical quantity</th>\n",
        "      <th colspan=\"2\" halign=\"left\">power</th>\n",
        "      <th colspan=\"2\" halign=\"left\">energy</th>\n",
        "      <th>voltage</th>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>type</th>\n",
        "      <th>active</th>\n",
        "      <th>apparent</th>\n",
        "      <th>active</th>\n",
        "      <th>apparent</th>\n",
        "      <th></th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>0</th>\n",
        "      <td> 0.698756</td>\n",
        "      <td> 1.366798</td>\n",
        "      <td> 2.320818</td>\n",
        "      <td>-1.592383</td>\n",
        "      <td> 0.155624</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>1</th>\n",
        "      <td>-0.817807</td>\n",
        "      <td> 2.438316</td>\n",
        "      <td> 1.541125</td>\n",
        "      <td>-0.393314</td>\n",
        "      <td> 0.693330</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 2,
       "text": [
        "physical quantity     power              energy             voltage\n",
        "type                 active  apparent    active  apparent          \n",
        "0                  0.698756  1.366798  2.320818 -1.592383  0.155624\n",
        "1                 -0.817807  2.438316  1.541125 -0.393314  0.693330"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "String"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "columns_strings = [str(p) + (',' + str(t) if t else '') for p,t in columns_tuples]\n",
      "\n",
      "pd.DataFrame(randn(2,5), columns=columns_strings)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr style=\"text-align: right;\">\n",
        "      <th></th>\n",
        "      <th>power,active</th>\n",
        "      <th>power,apparent</th>\n",
        "      <th>energy,active</th>\n",
        "      <th>energy,apparent</th>\n",
        "      <th>voltage</th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>0</th>\n",
        "      <td>-0.979919</td>\n",
        "      <td>-0.431717</td>\n",
        "      <td>-0.073521</td>\n",
        "      <td> 0.731000</td>\n",
        "      <td> 0.109189</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>1</th>\n",
        "      <td> 0.494156</td>\n",
        "      <td> 0.410478</td>\n",
        "      <td> 0.820294</td>\n",
        "      <td>-0.812069</td>\n",
        "      <td> 0.256516</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 3,
       "text": [
        "   power,active  power,apparent  energy,active  energy,apparent   voltage\n",
        "0     -0.979919       -0.431717      -0.073521         0.731000  0.109189\n",
        "1      0.494156        0.410478       0.820294        -0.812069  0.256516"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Read from CSV"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "CSV = \"\"\"0 1 2 3 4 5\n",
      "10 11 12 13 14 15\n",
      "20 21 22 23 24 25\n",
      "\"\"\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "MultiIndex"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "multiindex_df = pd.read_csv(StringIO(CSV), sep=\" \", names=columns_tuples)\n",
      "multiindex_df.columns.set_names(['physical quantity', 'type'], inplace=True)\n",
      "multiindex_df"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr>\n",
        "      <th>physical quantity</th>\n",
        "      <th colspan=\"2\" halign=\"left\">power</th>\n",
        "      <th colspan=\"2\" halign=\"left\">energy</th>\n",
        "      <th>voltage</th>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>type</th>\n",
        "      <th>active</th>\n",
        "      <th>apparent</th>\n",
        "      <th>active</th>\n",
        "      <th>apparent</th>\n",
        "      <th></th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>0 </th>\n",
        "      <td>  1</td>\n",
        "      <td>  2</td>\n",
        "      <td>  3</td>\n",
        "      <td>  4</td>\n",
        "      <td>  5</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>10</th>\n",
        "      <td> 11</td>\n",
        "      <td> 12</td>\n",
        "      <td> 13</td>\n",
        "      <td> 14</td>\n",
        "      <td> 15</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>20</th>\n",
        "      <td> 21</td>\n",
        "      <td> 22</td>\n",
        "      <td> 23</td>\n",
        "      <td> 24</td>\n",
        "      <td> 25</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 5,
       "text": [
        "physical quantity   power            energy            voltage\n",
        "type               active  apparent  active  apparent         \n",
        "0                       1         2       3         4        5\n",
        "10                     11        12      13        14       15\n",
        "20                     21        22      23        24       25"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "String"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "string_df = pd.read_csv(StringIO(CSV), sep=\" \", names=columns_strings)\n",
      "string_df"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr style=\"text-align: right;\">\n",
        "      <th></th>\n",
        "      <th>power,active</th>\n",
        "      <th>power,apparent</th>\n",
        "      <th>energy,active</th>\n",
        "      <th>energy,apparent</th>\n",
        "      <th>voltage</th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>0 </th>\n",
        "      <td>  1</td>\n",
        "      <td>  2</td>\n",
        "      <td>  3</td>\n",
        "      <td>  4</td>\n",
        "      <td>  5</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>10</th>\n",
        "      <td> 11</td>\n",
        "      <td> 12</td>\n",
        "      <td> 13</td>\n",
        "      <td> 14</td>\n",
        "      <td> 15</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>20</th>\n",
        "      <td> 21</td>\n",
        "      <td> 22</td>\n",
        "      <td> 23</td>\n",
        "      <td> 24</td>\n",
        "      <td> 25</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 6,
       "text": [
        "    power,active  power,apparent  energy,active  energy,apparent  voltage\n",
        "0              1               2              3                4        5\n",
        "10            11              12             13               14       15\n",
        "20            21              22             23               24       25"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Save to HDF5"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "store = pd.HDFStore('column_test.h5', 'w')\n",
      "store.put('string_df', string_df)\n",
      "store.put('multiindex_df', multiindex_df)\n",
      "store.close()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Read from HDF5"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "store = pd.HDFStore('column_test.h5', 'r')\n",
      "store.get('multiindex_df')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr>\n",
        "      <th>physical quantity</th>\n",
        "      <th colspan=\"2\" halign=\"left\">power</th>\n",
        "      <th colspan=\"2\" halign=\"left\">energy</th>\n",
        "      <th>voltage</th>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>type</th>\n",
        "      <th>active</th>\n",
        "      <th>apparent</th>\n",
        "      <th>active</th>\n",
        "      <th>apparent</th>\n",
        "      <th></th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>0 </th>\n",
        "      <td>  1</td>\n",
        "      <td>  2</td>\n",
        "      <td>  3</td>\n",
        "      <td>  4</td>\n",
        "      <td>  5</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>10</th>\n",
        "      <td> 11</td>\n",
        "      <td> 12</td>\n",
        "      <td> 13</td>\n",
        "      <td> 14</td>\n",
        "      <td> 15</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>20</th>\n",
        "      <td> 21</td>\n",
        "      <td> 22</td>\n",
        "      <td> 23</td>\n",
        "      <td> 24</td>\n",
        "      <td> 25</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 8,
       "text": [
        "physical quantity   power            energy            voltage\n",
        "type               active  apparent  active  apparent         \n",
        "0                       1         2       3         4        5\n",
        "10                     11        12      13        14       15\n",
        "20                     21        22      23        24       25"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "store.get('string_df')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr style=\"text-align: right;\">\n",
        "      <th></th>\n",
        "      <th>power,active</th>\n",
        "      <th>power,apparent</th>\n",
        "      <th>energy,active</th>\n",
        "      <th>energy,apparent</th>\n",
        "      <th>voltage</th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>0 </th>\n",
        "      <td>  1</td>\n",
        "      <td>  2</td>\n",
        "      <td>  3</td>\n",
        "      <td>  4</td>\n",
        "      <td>  5</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>10</th>\n",
        "      <td> 11</td>\n",
        "      <td> 12</td>\n",
        "      <td> 13</td>\n",
        "      <td> 14</td>\n",
        "      <td> 15</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>20</th>\n",
        "      <td> 21</td>\n",
        "      <td> 22</td>\n",
        "      <td> 23</td>\n",
        "      <td> 24</td>\n",
        "      <td> 25</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 9,
       "text": [
        "    power,active  power,apparent  energy,active  energy,apparent  voltage\n",
        "0              1               2              3                4        5\n",
        "10            11              12             13               14       15\n",
        "20            21              22             23               24       25"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "store.close()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Dump to CSV"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def print_csv(df):\n",
      "    output_csv = StringIO()\n",
      "    df.to_csv(output_csv)df.columns.set_names(LEVEL_NAMES, inplace=True)\n",
      "    print(output_csv.getvalue())\n",
      "    \n",
      "print_csv(multiindex_df)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "physical quantity,power,power,energy,energy,voltage\n",
        "type,active,apparent,active,apparent,\n",
        ",,,,,\n",
        "0,1,2,3,4,5\n",
        "10,11,12,13,14,15\n",
        "20,21,22,23,24,25\n",
        "\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print_csv(string_df)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        ",\"power,active\",\"power,apparent\",\"energy,active\",\"energy,apparent\",voltage\n",
        "0,1,2,3,4,5\n",
        "10,11,12,13,14,15\n",
        "20,21,22,23,24,25\n",
        "\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Select data"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Select single column"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# MultiIndex\n",
      "multiindex_df['power', 'active']"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 13,
       "text": [
        "0      1\n",
        "10    11\n",
        "20    21\n",
        "Name: (power, active), dtype: int64"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# String\n",
      "string_df['power,active']"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 14,
       "text": [
        "0      1\n",
        "10    11\n",
        "20    21\n",
        "Name: power,active, dtype: int64"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "select all power columns"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "multiindex_df['power'] # elegant way to get both 'active' and 'apparent' power data"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr style=\"text-align: right;\">\n",
        "      <th>type</th>\n",
        "      <th>active</th>\n",
        "      <th>apparent</th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>0 </th>\n",
        "      <td>  1</td>\n",
        "      <td>  2</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>10</th>\n",
        "      <td> 11</td>\n",
        "      <td> 12</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>20</th>\n",
        "      <td> 21</td>\n",
        "      <td> 22</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 15,
       "text": [
        "type  active  apparent\n",
        "0          1         2\n",
        "10        11        12\n",
        "20        21        22"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# or like this:\n",
      "multiindex_df['power']['active']"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 16,
       "text": [
        "0      1\n",
        "10    11\n",
        "20    21\n",
        "Name: active, dtype: int64"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# String:\n",
      "string_df[[col for col in string_df.columns if 'power' in col]]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr style=\"text-align: right;\">\n",
        "      <th></th>\n",
        "      <th>power,active</th>\n",
        "      <th>power,apparent</th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>0 </th>\n",
        "      <td>  1</td>\n",
        "      <td>  2</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>10</th>\n",
        "      <td> 11</td>\n",
        "      <td> 12</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>20</th>\n",
        "      <td> 21</td>\n",
        "      <td> 22</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 17,
       "text": [
        "    power,active  power,apparent\n",
        "0              1               2\n",
        "10            11              12\n",
        "20            21              22"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "list of all available 'power' AC types:"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "multiindex_df['power'].columns"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 18,
       "text": [
        "Index([u'active', u'apparent'], dtype='object')"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "[col.split(',')[1] for col in string_df.columns if 'power' in col]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 19,
       "text": [
        "['active', 'apparent']"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "get all 'active' physical quantities"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "multiindex_df.xs('active', level='type', axis=1) "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr style=\"text-align: right;\">\n",
        "      <th>physical quantity</th>\n",
        "      <th>power</th>\n",
        "      <th>energy</th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>0 </th>\n",
        "      <td>  1</td>\n",
        "      <td>  3</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>10</th>\n",
        "      <td> 11</td>\n",
        "      <td> 13</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>20</th>\n",
        "      <td> 21</td>\n",
        "      <td> 23</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 20,
       "text": [
        "physical quantity  power  energy\n",
        "0                      1       3\n",
        "10                    11      13\n",
        "20                    21      23"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# String:\n",
      "string_df[[col for col in string_df.columns if 'active' in col]]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr style=\"text-align: right;\">\n",
        "      <th></th>\n",
        "      <th>power,active</th>\n",
        "      <th>energy,active</th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>0 </th>\n",
        "      <td>  1</td>\n",
        "      <td>  3</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>10</th>\n",
        "      <td> 11</td>\n",
        "      <td> 13</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>20</th>\n",
        "      <td> 21</td>\n",
        "      <td> 23</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 21,
       "text": [
        "    power,active  energy,active\n",
        "0              1              3\n",
        "10            11             13\n",
        "20            21             23"
       ]
      }
     ],
     "prompt_number": 21
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Iterate"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "for (physical_quantity, ac_type), series in multiindex_df.iteritems():\n",
      "    print(physical_quantity, ac_type)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "power active\n",
        "power apparent\n",
        "energy active\n",
        "energy apparent\n",
        "voltage \n"
       ]
      }
     ],
     "prompt_number": 26
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}